import 'package:flutter_admin/utils/utils.dart';

class PurchaseOrder {
  String? id;
  String? name;
  String? contract;
  String? ordercode;
  String? orderdesc;
  String? dateOrder;
  String? dateOrderStart;
  String? dateOrderEnd;
  String? companyId;
  String? companyName;
  String? partnerId;
  String? partnerName;
  String? userId;
  String? userName;
  String? remark;
  String? createDateStart;
  String? createDateEnd;

  PurchaseOrder({
    this.id,
    this.name,
    this.contract,
    this.ordercode,
    this.orderdesc,
    this.dateOrder,
    this.dateOrderStart,
    this.dateOrderEnd,
    this.companyId,
    this.companyName,
    this.partnerId,
    this.partnerName,
    this.userId,
    this.userName,
    this.remark,
    this.createDateStart,
    this.createDateEnd,
  });

  PurchaseOrder copyWith({
    String? id,
    String? name,
    String? contract,
    String? ordercode,
    String? orderdesc,
    String? dateOrder,
    String? companyId,
    String? partnerId,
    String? userId,
    String? remark,
  }) {
    return new PurchaseOrder(
      id: id ?? this.id,
      name: name ?? this.name,
      contract: contract ?? this.contract,
      ordercode: ordercode ?? this.ordercode,
      orderdesc: orderdesc ?? this.orderdesc,
      dateOrder: dateOrder ?? this.dateOrder,
      companyId: companyId ?? this.companyId,
      partnerId: partnerId ?? this.partnerId,
      userId: userId ?? this.userId,
      remark: remark ?? this.remark,
    );
  }

  @override
  String toString() {
    return '''PurchaseOrder{
      id: id,
      name: name,
      contract: contract,
      ordercode: ordercode,
      orderdesc: orderdesc,
      dateOrder: dateOrder,
      companyId: companyId,
      partnerId: partnerId,
      userId: userId,
      remark: remark,
    }''';
  }

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      (other is PurchaseOrder &&
          runtimeType == other.runtimeType &&
          id == other.id &&
          name == other.name &&
          contract == other.contract &&
          ordercode == other.ordercode &&
          orderdesc == other.orderdesc &&
          dateOrder == other.dateOrder &&
          companyId == other.companyId &&
          partnerId == other.partnerId &&
          userId == other.userId &&
          remark == other.remark);

  factory PurchaseOrder.fromMap(Map<String, dynamic> map) {
    return new PurchaseOrder(
      id: map['id'] != false ? map['id'].toString() as String? : "",
      name: map['name'] != false ? map['name'].toString() as String? : "",
      contract:
          map['contract'] != false ? map['contract'].toString() as String? : "",
      ordercode: map['ordercode'] != false
          ? map['ordercode'].toString() as String?
          : "",
      orderdesc: map['orderdesc'] != false
          ? map['orderdesc'].toString() as String?
          : "",
      dateOrder: map['date_order'] != false
          ? Utils.getDate(date: map['date_order'].toString())
          : "",
      companyId: map['company_id'] != false
          ? map['company_id'].toString() as String?
          : "",
      companyName: map['company_id'] != false
          ? map['company_id'][1].toString() as String?
          : "",
      partnerId: map['partner_id'] != false
          ? map['partner_id'].toString() as String?
          : "",
      partnerName: map['partner_id'] != false
          ? map['partner_id'][1].toString() as String?
          : "",
      userId:
          map['user_id'] != false ? map['user_id'].toString() as String? : "",
      userName: map['user_id'] != false
          ? map['user_id'][1].toString() as String?
          : "",
      remark: map['remark'] != false ? map['remark'].toString() as String? : "",
    );
  }

  Map<String, dynamic> toMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'name': this.name,
      'contract': this.contract,
      'ordercode': this.ordercode,
      'orderdesc': this.orderdesc,
      'dateOrder': this.dateOrder,
      'companyId': this.companyId,
      'partnerId': this.partnerId,
      'userId': this.userId,
      'remark': this.remark,
    } as Map<String, dynamic>;
  }

  List toDomainList() {
    List list = [
      if (this.name != null && this.name != '')
        ['name', 'like', "%${this.name!}%"],
      if (this.dateOrderStart != null && this.dateOrderStart != '')
        [
          'date_order',
          '>=',
          this.dateOrderStart! + " 00:00:00"
        ],
      if (this.dateOrderEnd != null && this.dateOrderEnd != '')
        [
          'date_order',
          '<=',
          this.dateOrderEnd! + " 23:59:59",
        ],
    ] as List;
    // if (list.length == 0) {
    //   list.add(['id', '!=', null]);
    // }
    // ignore: unnecessary_cast
    return list;
  }

  Map<String, dynamic> toOdooMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'name': this.name,
      'contract': this.contract,
      'ordercode': this.ordercode,
      'orderdesc': this.orderdesc,
      'dateOrder': this.dateOrder,
      'companyId': this.companyId,
      'partnerId': this.partnerId,
      'userId': this.userId,
      'remark': this.remark,
    } as Map<String, dynamic>;
  }

//</editor-fold>

}
